/*
 * Copyright 2016-2036 the original author or authors.
 * 
 * COMMERCIAL USE OF THIS SOFTWARE WITHOUT WARRANTY IS NOT ALLOWED.
 * Use is subject to license terms! You can distribute a copy of this software
 * to others for free. This software is a non-profit and open-source project.
 * Any contribution to this project will make it better.
 * All rights reserved! Owned by Stephen Liu.
 * 
 */
package com.github.avatar.config.dubbo;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.MonitorConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @author Stephen Liu
 * @since 2017/6/27
 */
@EnableConfigurationProperties(value = DubboConfig.class)
public class DubboBaseConfig {

    @Autowired
    protected DubboConfig dubboConfig;

    @Bean
    public RegistryConfig registry() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress(dubboConfig.getAddress());
        registryConfig.setProtocol(dubboConfig.getRegistryProtocol());
        return registryConfig;
    }

    @Bean
    public ApplicationConfig application() {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName(dubboConfig.getServiceName());
        return applicationConfig;
    }

    @Bean
    public MonitorConfig monitor() {
        MonitorConfig monitorConfig = new MonitorConfig();
        monitorConfig.setProtocol(dubboConfig.getMonitorProtocol());
        return monitorConfig;
    }
}
